/*************************************************************
 * @file                        system_info.c        
 * @brief
 *
 *
 * @version   Version
 * @author    SealedGhost
 * @data
 *************************************************************/
	
	
	#include  "system_info.h"
	
	#include "flash.h"
	
	#define PHONE_NUMBER 6
    
    
//	#define PHONE_ID_8888888
	//#define PHONE_ID_7777777
	//#define PHONE_ID_6666666
	
	/** @addtogroup     系统信息
 *   
 *   @{
 */
	
	


	
	
	
	static SysInfo SystemInfo  = {0};
	
	
	
	
	/**@brief  得到本机呼号
  * 
  *
  * @return void
  * @note
  */
 inline  uint32_t SysInfo_GetId()
	{
		 return SystemInfo.phoneId;
	}

	
	
	/**@brief 得到本机密码
  * 
  *
  * @return void
  * @note
  */
	inline  uint16_t SysInfo_GetPassword()
	{
		 return SystemInfo.pwd;
	}
	
	
	
	/**@brief  得到版本信息
  * 
  *
  * @return void
  * @note
  */
	void SysInfo_GetVersion(VersionInfo* ver)
	{
		 if(ver){
				 memcpy(ver, &SystemInfo.version, sizeof(VersionInfo));
			}
	}
	


	
	/**@brief  从Flash中载入系统信息
  * 
  *
  * @return void
  * @note
  */
	void SysInfo_Load()
	{
		 SPIFlashSectionRead((uint8_t*)&SystemInfo, FLASH_ADDRESS_SYS_INFO / 0x1000, sizeof(SystemInfo));
        
		 if(SystemInfo.phoneId == 0  ||  SystemInfo.phoneId == UINT32_MAX || SystemInfo.pwd != 59118){
				 SystemInfo.phoneId  = 1346739;
				 SystemInfo.pwd      = 59118;
				 
				 /// 版本号 1.0.0
				 SystemInfo.version.major  = 1; 			
				 SystemInfo.version.minor  = 0;
				 SystemInfo.version.revise = 0;
				 SystemInfo.version.day  = 20;
				 SystemInfo.version.month = 6;
				 SystemInfo.version.year  = 2017;
				 SystemInfo.version.state  = VER_STATE_ALPHA;
                 SysInfo_Store();				
		}
        else{
//            printf("sysInfo Load success!\n");
        }
        
#if (PHONE_NUMBER == 6)
        SystemInfo.phoneId  = 6666666;	
#elif (PHONE_NUMBER == 7) 
        SystemInfo.phoneId  = 7777777;	
#elif (PHONE_NUMBER == 8) 
        SystemInfo.phoneId  = 8888888;	        
#endif        
	}
	
	
	
	
	/**@brief  系统信息存储到Flash
  * 
  *
  * @return void
  * @note
  */
 void SysInfo_Store()
	{
		  SPIFlashSectionWrite((uint8_t*)&SystemInfo, FLASH_ADDRESS_SYS_INFO / 0x1000, sizeof(SystemInfo));
	}

/** @} */


	